package org.jaronsource.sample.web.controller;

import static org.springframework.web.bind.annotation.RequestMethod.GET;
import static org.springframework.web.bind.annotation.RequestMethod.POST;

import org.jaronsource.framework.core.dao.support.Page;
import org.jaronsource.framework.core.service.SearchForm;
import org.jaronsource.sample.domain.Contact;
import org.jaronsource.sample.service.ContactService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

@RequestMapping ( "/contact")
@Controller
public class ContactStaticController {

	final Logger logger = LoggerFactory.getLogger( ContactStaticController.class );

	@Autowired
	MessageSource messageSource;

	@Autowired
	private ContactService contactService;

	@RequestMapping ( value = "/list.static", method = { GET, POST })
	public String list( @ModelAttribute SearchForm searchForm, Model model ) {

		Page<Contact> contactPage = contactService.findPage( searchForm );
		model.addAttribute( "contactPage", contactPage );

		return "contactstatic/list";
	}

	@RequestMapping ( value = "/{recordId}/detail.static", method = GET)
	public String show( @PathVariable ( "recordId") Integer recordId,
						Model model ) {
		Contact contact = contactService.findByPk( recordId );
		model.addAttribute( "contact", contact );
		return "contactstatic/show";
	}

}
